package com.unionftech.common.common.adapter

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.unionftech.common.R
import com.unionftech.common.common.bean.BaseCountryInfo
import com.unionftech.common.common.bean.CountryInfo


class CountrySelectAdapter(list: MutableList<BaseCountryInfo>) :
    BaseMultiItemQuickAdapter<BaseCountryInfo, BaseViewHolder>(list) {
    init {
        addItemType(
            BaseCountryInfo.TYPE_COUNTRY_CHAR_INFO,
            R.layout.layout_select_country_code_title_item
        )
        addItemType(BaseCountryInfo.TYPE_COUNTRY_INFO, R.layout.layout_select_country_code_item)
    }

    override fun convert(holder: BaseViewHolder, item: BaseCountryInfo) {
        if (item.itemType == BaseCountryInfo.TYPE_COUNTRY_CHAR_INFO) {
            holder.setText(R.id.tv_pinyin_title, item.firstChar)
        } else if (item.itemType == BaseCountryInfo.TYPE_COUNTRY_INFO) {
            val countryInfo = item as CountryInfo
            holder.setText(R.id.tv_country_name, countryInfo.nameEn.replace("\n", ""))
            holder.setText(R.id.tv_country_code, countryInfo.areaCode)
            holder.setGone(R.id.view_divider, !item.isLast)
        }
    }
}